﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Extention.ENode.Rpc.Routing.Impl;
using Extention.ENode.Rpc.Runtime.Communally.Entitys.Address;

namespace Extention.ENode.Rpc.Routing
{
    /// <summary>
    /// 抽象的服务路由发现者
    /// </summary>
    public interface IServiceRouteManager
    {
        /// <summary>
        /// 服务路由被创建
        /// </summary>
        event EventHandler<ServiceRouteEventArgs> Created;

        /// <summary>
        /// 服务路由被删除
        /// </summary>
        event EventHandler<ServiceRouteEventArgs> Removed;

        /// <summary>
        /// 服务路由被修改
        /// </summary>
        event EventHandler<ServiceRouteChangedEventArgs> Changed;

        /// <summary>
        /// 获取所有可用的服务路由信息
        /// </summary>
        /// <returns>服务路由集合</returns>
        Task<IEnumerable<ServiceRoute>> GetRoutesAsync();

        /// <summary>
        /// 获取单条可用路由
        /// </summary>
        /// <param name="serviceId"></param>
        /// <returns></returns>
        Task<ServiceRoute> GetRouteAsync(string serviceId);
        /// <summary>
        /// 获取负载信息
        /// </summary>
        /// <param name="serverName"></param>
        /// <returns></returns>
        Task<IEnumerable<IpAddressModel>> GetBalanceAsync(string serverName);


        /// <summary>
        /// 获取所有服务的key
        /// </summary>
        /// <returns></returns>
        Task<List<string>> GetServerKey();

        /// <summary>
        /// 设置服务路由
        /// </summary>
        /// <param name="routes">服务路由集合</param>
        /// <param name="serviceInfo">rpc信息</param>
        /// <returns>一个任务</returns>
        Task SetRoutesAsync(IEnumerable<ServiceRoute> routes, IpAddressModel serviceInfo);


        /// <summary>
        /// 设置负载信息
        /// </summary>
        /// <param name="serverInfo">rpc信息</param>
        /// <returns></returns>
        Task SetBalanceAsync(IpAddressModel serverInfo);

        /// <summary>
        /// 清空所有的服务路由
        /// </summary>
        /// <returns>一个任务</returns>
        Task ClearAsync(IpAddressModel serverInfo);
    }
}